package com.zkca.xf.presenter;

import com.trello.rxlifecycle2.LifecycleProvider;
import com.trello.rxlifecycle2.android.ActivityEvent;
import com.zkca.xf.base.BasePresenter;
import com.zkca.xf.manager.DataManager;
import com.zkca.xf.model.javabean.FaultJobLBean;
import com.zkca.xf.model.javabean.JobLBean;
import com.zkca.xf.model.javabean.uploadbean.RequestInspect;
import com.zkca.xf.view.FaultJobLView;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.observers.DefaultObserver;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by li on 2018/12/5.
 */

public class FaultJobLPresenter extends BasePresenter {
    private DataManager dataManager;
    private FaultJobLView faultJobLView;
    public FaultJobLPresenter(LifecycleProvider<ActivityEvent> provider,FaultJobLView faultJobLView) {
        super(provider);
        dataManager=DataManager.getInstance();
        this.faultJobLView=faultJobLView;
    }

    public void GetFault(RequestInspect requestInspect) {
        dataManager.GetFault(requestInspect)
                .subscribeOn(Schedulers.io())// 在子线程中进行Http访问
                .observeOn(AndroidSchedulers.mainThread())// UI线程处理返回接口
                .compose(getProvider().<FaultJobLBean>bindUntilEvent(ActivityEvent.DESTROY))// onDestroy取消订阅
                .subscribe(new DefaultObserver<FaultJobLBean>() {// 订阅
                    @Override
                    public void onNext(FaultJobLBean s) {
                        faultJobLView.FaultJob(s);
                    }

                    @Override
                    public void onError(Throwable e) {
                        faultJobLView.showError(e.getMessage());
                    }

                    @Override
                    public void onComplete() {
                        faultJobLView.hideProgressDialog();
                    }
                });
    }


}
